<?php
	
	$_userid = $_userid == 1 && $userid  ? $userid : $_userid; // 管理员编辑其他会员信息权限
	
	$action = $action ? $action : 'manage';
	
	$company_user_infos = $db->get_one("SELECT * FROM `".DB_PRE."member_company` WHERE `userid`='$_userid'");
	switch($action){
		case 'manage':
			if(!$_userid) showmessage('您还没有登陆，即将跳转到登陆页面',url("?module=member&action=login&forward=".urlencode(URL)));
			//首页 公司介绍 产品展示  商机 人才招聘 在线留言 联系方式 
			if($dosubmit)
			{
				if($newcatname)
				{
					$number = count($usermenu['catname']);
					$usermenu['catname'][] = $newcatname;
					$usermenu['linkurl'][] = $linkurl;
					$usermenu['use'][$number] = 1;
				}
				
				$arraymenu['system'] = $system;
				foreach($usermenu['linkurl'] AS $_key=>$_value)
				{
					if(trim($_value))
					{
						$usermenu_temp['linkurl'][] = $_value;
						$usermenu_temp['catname'][] = $usermenu['catname'][$_key];
					}
				}
				$arraymenu['usermenu'] = $usermenu_temp;
				$menustring = array2string($arraymenu);
				//echo "UPDATE `".DB_PRE."member_company` SET `menu`='$menustring' WHERE `userid`='$_userid'";exit();
				$db->query("UPDATE `".DB_PRE."member_company` SET `menu`='$menustring' WHERE `userid`='$_userid'");
				showmessage('菜单更新成功',url("?module=$module&file=$file&action=$action&userid=$_userid"));
			}
			else
			{
				if(empty($company_user_infos['menu']))
				{
					//$arraymenu = cache_read('menu.inc.php','includes/');
					$arraymenu = array (
					  'system' => 
					  array (
						'use' => 
						array (
						  1 => '1',
						  2 => '1',
						  3 => '1',
						  4 => '1',
						  5 => '1',
						  6 => '1',
						  7 => '1',
						  8 => '1',
						  9 => '1',
						),
						'catname' => 
						array (
						  1 => '首页',
						  2 => '公司介绍',
						  3 => '公司新闻',
						  4 => '产品展示',
						  5 => '商机在线',
						  6 => '人才招聘',
						  7 => '资质证书',
						  8 => '在线留言',
						  9 => '联系方式',
						),
					  ),
					  'usermenu' => 
					  array (
						'catname' => 
						array (
						  0 => 'phpcms官方',
						),
						'linkurl' => 
						array (
						  0 => 'http://www.phpcms.cn',
						),
						'use' => 
						array (
						  1 => '0',
						),
					  ),
					);
				}
				else
				{
					$arraymenu = string2array($company_user_infos['menu']);
				}
				$system = $arraymenu['system'];
				$usermenu = $arraymenu['usermenu'];
				
				foreach($system['catname'] AS $k=>$v)
				{
					$checked = '';
					if($system['use'][$k]) $checked = 'checked';
					$strings .= '
						<tr>
						<td class="align_c"><input type="checkbox" value="1" name="system[use]['.$k.']" '.$checked.'> </td>
						<td class="align_c"><input name="system[catname]['.$k.']" type="text" size="15" maxlength="20" require="true" datatype="limit" min="1" max="50"  msg="字符长度范围必须为1到50位"  mode="1" value="'.$system['catname'][$k].'"></td>
						<td class="align_c"></td>
					</tr>';
				}
				foreach($usermenu['catname'] AS $k=>$v)
				{
					$checked = '';
					if($usermenu['use'][$k]) $checked = 'checked';
					$strings .= '
						<tr>
						<td class="align_c"><input type="checkbox" value="1" name="usermenu[use]['.$k.']" '.$checked.'> </td>
						<td class="align_c"><input name="usermenu[catname]['.$k.']" type="text" size="15" maxlength="20" value="'.$usermenu['catname'][$k].'"></td>
						<td class="align_c"><input name="usermenu[linkurl]['.$k.']" type="text" size="55" maxlength="20" value="'.$usermenu['linkurl'][$k].'"></td>
					</tr>';
				}
				//$number = count($usermenu['catname']);
			}
			include template('menu_manage.html','yellowpage');
		break;
	
		case 'update':
				if(!$_userid) showmessage('您还没有登陆，即将跳转到登陆页面',url("?module=member&action=login&forward=".urlencode(URL)));
			include template('menu_manage.html','yellowpage');
			break;
	}
?>